#include "tasks.hpp"

#include <iomanip>
#include <ios>
#include <iostream>
#include <ostream>
#include <vector>

#include "student.hpp"

void Task1() {
    std::vector<Student> students;
    int n = 0;
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::string name;
        double math_score;
        double chinese_score;
        double english_score;
        std::cin >> name >> chinese_score >> math_score >> english_score;
        students.push_back(Student(name, chinese_score, math_score, english_score));
    }
    std::cout << std::fixed << std::setprecision(2);
    for (const auto& i : students) {
        std::cout << std::left << std::setw(10) << i.GetName() << std::right << std::setw(8)
                  << i.GetChineseScore() << std::right << std::setw(8) << i.GetMathScore()
                  << std::right << std::setw(8) << i.GetEnglishScore() << std::right << std::setw(8)
                  << i.GetAverageScore() << std::right << std::setw(11)
                  << (i.GetIsExcellent() ? "Excellent" : "") << std::endl;
    }
}

void Task2(const char* str) { std::cout << CountVowels(str) << std::endl; }

void Task3() {
    std::cout << std::fixed << std::setprecision(2);
    int a = 0;
    int b = 0;
    char op = ' ';
    std::cin >> a >> b >> op;
    std::cout << Square(a) << std::endl;
    std::cout << power(a, b) << std::endl;
    std::cout << Calc(a, b, op) << std::endl;
}

void Task4() {
    int a = 0;
    int b = 0;
    std::cin >> a >> b;
    
    MySwap(a, b);
    std::cout << a << " " << b << std::endl;
}

int CountVowels(const char* str) {
    const char* tmp = str;
    int count = 0;
    while (*tmp != '\0') {
        if (*tmp == 'a' || *tmp == 'e' || *tmp == 'i' || *tmp == 'o' || *tmp == 'u') {
            count++;
        }
        tmp++;
    }
    return count;
}
inline double Square(double x) {
    return x * x;
}

double power(double base, int exponent = 2) {
    int ans = base;
    for (int i = 1; i < exponent; i++) {
        ans *= base;
    }
    return ans;
}

double Calc(double a, double b, char op) {
    switch (op) {
        case '+':
            return a + b;
        case '-':
            return a - b;
        case '*':
            return a * b;
        case '/':
            if (b != 0) {
                return a / b;
            } else {
                std::cerr << "Error: Division by zero." << std::endl;
                return 0;
            }
        default:
            std::cerr << "Error: Invalid operator." << std::endl;
            return 0;
    }
}

double Calc(int a, int b, char op) {
    return Calc(static_cast<double>(a), static_cast<double>(b), op);
}

void MySwap(int& a, int& b) {
    int temp = a;
    a = b;
    b = temp;
}